package com.cloud.example.business.flow.controller.depend.dependnew.worker;


import com.cloud.async.flow.callback.ICallback;
import com.cloud.async.flow.callback.IWorker;
import com.cloud.async.flow.worker.WorkResult;
import com.cloud.async.flow.wrapper.WorkerWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;


public class DeWorker2 implements IWorker<User, String>, ICallback<User, String> {

    /**
     * logger
     */
    private final Log logger = LogFactory.getLog(getClass());


    @Override
    public String action(User object, Map<String, WorkerWrapper> allWrappers) {
        WorkResult second = allWrappers.get("second").getWorkResult();
        logger.info("worker2 入参:" + second.getResult());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        User user1 = (User) allWrappers.get("second").getWorkResult().getResult();
        return user1.getName() + " worker2 add";
    }

    @Override
    public String defaultValue() {
        return "default";
    }

    @Override
    public void begin() {
    }

    @Override
    public void result(boolean success, User param, WorkResult<String> workResult) {
        logger.info("worker2 的结果是：" + workResult.getResult());
    }

}
